package com.verbetia.mbrainz.search;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class BrainzSearch extends HttpServlet {
	
	public BrainzSearch()
	{}
	
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException 
	{
		ArrayList<ResultItem> results = null;
		PrintWriter out = response.getWriter();
        
        String q = request.getParameter("q");
        
        if (q!=null || !q.equals(""))
        {
        	try {
        		results = TrackSearch.getInstance().searchTrack(q);        		        		    
        	} catch (Exception e)
        	{        		
        		System.out.println(e);
        	}
        	
        	for (ResultItem i : results)
        	{
        		out.println(i.getTitle() + "  / " +  i.getArtist() + " (Score: " + i.getScore() + ")");
        	}
        		
        	
        }                        
        
        out.close();

	}
	
	
	public void init() throws ServletException {
		
		
	}


}


